<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%
	String bathPath = request.getContextPath();
	pageContext.setAttribute("bathPath", bathPath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<script type="text/javascript" src="${bathPath}/js/jquery-1.9.1.min.js" ></script>
<link rel="stylesheet" href="${bathPath}/frame/layui/css/layui.css"  media="all">
<script src="${bathPath}/frame/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<link rel="stylesheet" href="${bathPath}/layui_ext/dtree/dtree.css">
<link rel="stylesheet" href="${bathPath}/layui_ext/dtree/font/dtreefont.css">
</head>
<style type="text/css"> 
.layui-table-cell .layui-form-checkbox[lay-skin="primary"]{
     top: 50%;
     transform: translateY(-50%);    
}
</style>
<body>
<div class="layui-tab" lay-filter="demo" lay-allowclose="true" style="height:490px;width:910px;margin-left:20px;">
  <ul class="layui-tab-title">
    <li lay-id="22">角色管理</li>
  </ul>
  <div class="layui-tab-content" style="height:450px; width:910px">
    <div class="layui-tab-item layui-show" >
  <form id="myform" class="layui-form layui-form-pane">
 <div class="demoTable" style="margin-top: 60px;margin-left:30px;"> 
</div> 
</form>
<!--增加/删除  -->
<div >
<span><button  class="layui-btn site-demo-active layui-btn-sm " style="margin-top:-90px;position:relative;" onclick="zengjia()">增加</button></span> 
<span><button  class="layui-btn site-demo-active layui-btn-sm " style="margin-top:-90px;" onclick="shanchu(nid)">删除</button></span>
<span><button  class="layui-btn site-demo-active layui-btn-sm " style="margin-top:-90px;" onclick="xiugai(nid)">修改</button></span>
</div>

<!--树形  -->
<div style="height:405px;width:200px;overflow:auto; margin-top:-30px; margin-left:-20px;" id="toolbarDiv">
	<ul id="demoTree1" class="dtree" data-id="0" style="width:180px;height:400px;"></ul>
</div>
<!-- 页面 -->
<div>
<iframe id="myIframe" name="mainIframe" frameborder="0" style="width:740px;height:460px;min-width:740px;margin-left:185px;margin-top:-450px;"></iframe>
</div>
 <table class="layui-hide"  id="demo"></table>
<table class="layui-hide"  id="test"  lay-filter="test"></table>
</div>
<script src="${bathPath}/frame/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
var jiedian;
var nid;
$(function(){
	
	$.ajax({
		type:"POST",
		async:false,  //默认true,异步
		url:"${bathPath}/aDKManageRole/selectAll.action",
		success:function(data){
	      jiedian=data.data;
	      layui.config({
			  base: '${bathPath}/layui_ext/dtree/' //配置 layui 第三方扩展组件存放的基础目录
			}).extend({
			  dtree: 'dtree' //定义该组件模块名
			}).use(['element','layer', 'dtree'], function(){
				var layer = layui.layer,
				    dtree = layui.dtree,
				    $ = layui.$;
				dtree.render({
				  elem: "#demoTree1",  //绑定元素
				  data: demoData,  //数据
				  dot: false,  //隐藏小圆点
				  toolbarScroll:"#toolbarDiv" //加滚动条
				});

			        //单击节点 监听事件
			          dtree.on("node('demoTree1')" ,function(param){
			        	  nid=param.param.nodeId;
				      $("#myIframe").attr("src","${bathPath}/aDKManageRole/findId2.action?id="+param.param.nodeId);
				});  
			});
 
	    }
	});
	
	
 var demoData  = function(){
	  var arr = [];
	  
   arr.push({
	    	 "id":jiedian[0].id,
	  		"title": jiedian[0].name,
	  		"isLast": false,
	  		"level": "1",
	      });  
	  
	  arr[0].children=function(){
          var arr = [];
        $.each(jiedian,function(index,bean){ 
        if(index>0){
             arr.push({
     	    	"id":bean.id,
    	  		"title": bean.name,
    	  		"isLast": true,
    	  		"level": "2",
	            });
         }
          }); 
          return arr;
      }();
    return arr;
 }();
 
}); 


//增加弹出框
function zengjia(){
	parent.layer.open({
		  title:'增加角色',
		  type: 2,
		  area:['451px', '180px'],
		  offset:['230px','550px'],
		  content: '${bathPath}/aDKManageRole/index1.action',
		  success:function(layero,index){
			  layer.iframeAuto(index);
		  }
		  }); 
}

//修改弹出框
function xiugai(nid){
	parent.layer.open({
		  title:'修改角色',
		  type: 2,
		  area:['451px', '180px'],
		  offset:['230px','550px'],
		  content: '${bathPath}/aDKManageRole/findId.action?id='+nid,
		  success:function(layero,index){
			  layer.iframeAuto(index);
		  }
		  }); 
}

//删除
function shanchu(nid){
	alert(nid);
	layer.confirm("是否要删除？", {btn: ['是', '否'], title: "提示"}, function(){
		$.ajax({
			 type:"POST",
			 async:false,
			 dataType:JSON,
		     url:"${bathPath}/aDKManageRole/delete.action?id="+nid,
		     success:function(data){
		    	 if(data!="SUCCESS"){
						layer.msg(data);	
					}
		}
		 });
		layer.close(layer.index);
		location.reload();
	});	
}
</script>
</body>
</html>